package com.obtk.byproperty.controller;

import com.obtk.byproperty.pojo.JsonResult;
import com.obtk.byproperty.pojo.Owner;
import com.obtk.byproperty.service.OwnerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/owner")
public class OwnerController {

    @Autowired
    private OwnerService ownerService;

    @RequestMapping("/getCommunityName")
    public List<String> getCommunityName(){
       List<String> ownerCommunity=  ownerService.getCommunityName();
        return ownerCommunity;
    }

    @RequestMapping("/getBuildingName")
    public List<String> getBuildingName(){
       List<String> ownerBuildingName=ownerService.getBuildingName();
       return ownerBuildingName;
    }
    @RequestMapping("/bindOwner")
    public JsonResult BindOwner(Owner owner){
        System.out.println(owner);
        Owner owners= ownerService.selectOwner(owner);

        if(owners==null){
            return JsonResult.fail(null).put("code",0).put("msg","绑定用户失败");
        }
        return JsonResult.success(owners).put("code",1).put("msg","绑定用户成功");
    }
    @RequestMapping("selectOpenid")
    public Owner selectOpenid(String openid){
       Owner owner= ownerService.selectOpenid(openid);
       return owner;
    }
}
